package com.xiepei.day01;

/**
 * Student类 - 演示Java继承概念
 * 继承：子类继承父类的属性和方法，并可以添加自己的特有属性和方法
 */
public class Student extends Person implements Learnable {
    // 子类特有的属性
    private String studentId;
    private String major;
    private double gpa;
    
    // 构造方法
    public Student(String name, int age, String gender, String studentId, String major) {
        // 调用父类构造方法
        super(name, age, gender);
        this.studentId = studentId;
        this.major = major;
        this.gpa = 0.0;
    }
    
    // Getter和Setter方法
    public String getStudentId() {
        return studentId;
    }
    
    public void setStudentId(String studentId) {
        this.studentId = studentId;
    }
    
    public String getMajor() {
        return major;
    }
    
    public void setMajor(String major) {
        this.major = major;
    }
    
    public double getGpa() {
        return gpa;
    }
    
    public void setGpa(double gpa) {
        if (gpa >= 0.0 && gpa <= 4.0) {
            this.gpa = gpa;
        }
    }
    
    // 子类特有的方法
    public void study() {
        System.out.println(getName() + "正在学习" + major + "专业");
    }
    
    public void takeExam() {
        System.out.println(getName() + "正在参加考试");
    }
    
    public void updateGpa(double newGpa) {
        setGpa(newGpa);
        System.out.println(getName() + "的GPA更新为：" + gpa);
    }
    
    // 实现Learnable接口的方法
    @Override
    public void learn() {
        System.out.println(getName() + "学生正在认真学习" + major + "课程");
    }
    
    @Override
    public void takeNotes() {
        System.out.println(getName() + "学生正在做笔记");
    }
    
    // 重写父类方法 - 方法重写(Override)
    @Override
    public void introduce() {
        System.out.println("大家好，我是学生" + getName() + "，学号是" + studentId + 
                          "，专业是" + major + "，GPA是" + gpa);
    }
    
    // 重写toString方法
    @Override
    public String toString() {
        return "Student{" +
                "name='" + getName() + '\'' +
                ", age=" + getAge() +
                ", gender='" + getGender() + '\'' +
                ", studentId='" + studentId + '\'' +
                ", major='" + major + '\'' +
                ", gpa=" + gpa +
                '}';
    }
}
